package com.chat.service;

import com.chat.Local;
import com.chat.common.Message;
import com.chat.common.MessageType;
import com.chat.common.User;
import com.chat.view.FriendListData;
import com.chat.view.GroupVerifyView;
import com.chat.view.MainWindowView;
import javafx.application.Platform;
import javafx.collections.ObservableList;

import java.util.ArrayList;

import static com.chat.view.MainWindowController.friend;

/*
获取好友列表
 */
public class GetFriendList {
        GetFriendList(){

        }
       public GetFriendList(ObservableList<FriendListData> a){
              Message msg=new Message();
              User user=new User();
              user.setUsername(Local.user.getUsername());
              msg.setMesType(MessageType.MESSAGE_GET_FRIEND_LIST);
              msg.setData(user);
              ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
              clientConnectServerThread.send(msg);
       }
       public void SetFriendList(ArrayList<User> a){
            Local.friendlist=a;
           Platform.runLater(new Runnable() {
               @Override
               public void run() {
                   friend.add(new FriendListData("验证消息","验证消息"," ","1","1"));
                   for(int i=0;i<a.size();i++)
                   {
                       friend.add(new FriendListData(a.get(i).getNickname(),a.get(i).getUsername(),a.get(i).getQianming(),"1",a.get(i).getStatus()));
                   }
               }
           });

       }
}
